// 2025/5/27
// dd爱科学

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n; cin >> n;
    string str; cin >> str;
    vector<int> tail;
    for(int i = 0; i < n; i++)
    {
        if(tail.empty() || str[i] >= tail.back())
            tail.emplace_back(str[i]);
        else
        {
            int left = 0, right = tail.size() - 1, aim = right;
            while(left <= right)
            {
                int mid = (left + right) >> 1;
                if(tail[mid] >= str[i])
                {
                    aim = mid;
                    right = mid - 1;
                }
                else
                    left = mid + 1;
            }
            tail[aim] = str[i];
        }
    }
    cout << n - tail.size() << endl;
}
// 64 位输出请用 printf("%lld")